package br.ufpb.bioinfo.main;

import br.ufpb.bioinfo.dao.DAOOrganism;
import br.ufpb.bioinfo.model.Gene;
import br.ufpb.bioinfo.model.Molecule;
import br.ufpb.bioinfo.model.Organism;

public class Main {

	public static void main(String[] args) {

		DAOOrganism dao = new DAOOrganism();
		Organism org = dao.find(Long.parseLong("1"));
		doCount(org);
	}


	public static int doCount(Organism organism){

		for (Molecule m : organism.getMolecules()) {
			for (Gene g : m.getGenes()) {
				System.out.println("GENE Name: " + g.getName() + " Property G+C: " + GC_Property(g.getSequence()));
				System.out.println("GENE Protein E+K/G+H : " + EKQH(g.getProtein().getSequence()));					
			}
		}
		return 0;
	}

	public static int GC_Property(String sequence){
		int G=0;
		int C=0;

		char[] counter = new char[sequence.length()];
		counter = sequence.toCharArray();
		for (int i = 0; i < counter.length; i++) {
			switch (counter[i]) {
			case 'g': G++; 		
			break;
			case 'c': C++;
			break;
			}
		}
		return G+C;
	}

	public static int EKQH(String sequence){
		int e=0;
		int k=0;
		int q=0;
		int h=0;

		char[] counter = new char[sequence.length()];
		counter = sequence.toCharArray();
		for (int i = 0; i < counter.length; i++) {
			switch (counter[i]) {
			case 'E': e++; 		
			break;
			case 'K': k++;
			break;
			case 'Q': q++; 		
			break;
			case 'H': h++;
			break;
			}
		}
		
		try {
			return (e+k)/(q+h);
		} catch (ArithmeticException ex) {
			return 0;
		}
		
	}


}
